import { _decorator, Component, Label, Node } from 'cc';
import { AudioMgr, SoundName } from '../Mgr/AudioMgr';
import { UIMgr } from '../Mgr/UIMgr';
import { AssetList, Global } from '../Global';
import { LocalStorageMgr } from '../Mgr/LocalStorageMgr';
const { ccclass, property } = _decorator;

@ccclass('GameEnd')
/**
 * 游戏结束层
 */
export class GameEnd extends Component {

    //受伤文本
    @property(Label)
    private HurtText: Label = null;

    //奖励牌文本
    @property(Label)
    private RewardText: Label = null;

    //剩余文本
    @property(Label)
    private SurpleText: Label = null;

    //多余造成伤害
    @property(Label)
    private OverText: Label = null;

    //总分
    @property(Label)
    private TotalText: Label = null;

    /**
     * 更新游戏分数
     */
    public UpdateScore(_surple: number) {
        this.HurtText.string = Global.HurtScore.toString();
        this.RewardText.string = Global.CatGiveScore.toString();
        this.SurpleText.string = _surple.toString();
        this.OverText.string = Math.floor(Global.HurtOver).toString();

        let all_score: number = Global.HurtScore + Global.CatGiveScore + _surple + Global.HurtOver;
        this.TotalText.string = (all_score).toString();

        LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.ALLSCORE += all_score;

        if (LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.BESTSCORE < all_score) LocalStorageMgr.Instance.LOCAL_STORAGE_DATA.BESTSCORE = all_score;
        LocalStorageMgr.Instance.UpdateLocalStroage();
    }

    /**
     * 点击回到首页按钮
     */
    public GoLogin() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        UIMgr.Instance.UdpateScene(AssetList.Scene.LoginScene);
        UIMgr.Instance.HidePop(AssetList.Pop.GAMEEND);
    }

}


